package com.itheima.d3_udp2.ZengUdpTest;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.Scanner;

/**
 * @ClassName Client
 * @Author 16799
 * @Date 2025/9/25 23:38
 * @Version 1.0
 * @Description TODO
 **/
public class Client {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket();

        Scanner sc = new Scanner(System.in);
        while (true){
            System.out.println("请输入： ");
            String msg = sc.next();

            if (msg.equals("exit")){
                System.out.println("已关闭客户端");
                socket.close();
                break;
            }

            byte[] bytes = msg.getBytes();
            DatagramPacket packet = new DatagramPacket(bytes,bytes.length,
                    InetAddress.getLocalHost(),6622);

            socket.send(packet);
        }

    }
}
